package com.bw.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bw.entity.ZkShopping;
import com.bw.service.IZkShoppingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author szg
 * @since 2020-05-27
 */
@RestController
@CrossOrigin
@RequestMapping("/shop")
public class ZkShoppingController {

    @Autowired
    private IZkShoppingService shoppingService;


    @GetMapping("/slist")
    public List<ZkShopping> find(){
        System.out.println("展示商品下拉框");
        return shoppingService.list();
    }
    @GetMapping("/find/{id}")
    public ZkShopping find(@PathVariable Integer id){
        System.out.println("根据数据回显");
        ZkShopping shop=shoppingService.getById(id);
        return shop;
    }
    @PostMapping("/up/{gysid}/{num}")
    public String up(@PathVariable Integer gysid,@PathVariable Integer num){
        System.out.println("开始购买");
        ZkShopping shop=shoppingService.getById(gysid);
        System.out.println(shop.toString());
        shop.setNum(shop.getNum()-num);
        shoppingService.saveOrUpdate(shop);
        return "修改成功";
    }

}
